//
//  YZMWelController.swift
//  YZMweibo
//
//  Created by Simon on 16/4/19.
//  Copyright © 2016年 Simon. All rights reserved.
//

import UIKit
import SDWebImage

class YZMWelController: UIViewController {
    
    override func loadView() {
        
        view = backImageView
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        setHeadImageViewAnim()
    }
    
    private func setHeadImageViewAnim(){
        // 更新我们的headImageView 约束
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            // 需要刷新布局
            self.view.layoutIfNeeded()
            
        }) { (_) -> Void in
            
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.messageLabel.alpha = 1
                }, completion: { (_) -> Void in
                    NSNotificationCenter.defaultCenter().postNotificationName(SwitchDefaultVcNSNotification, object: "welcome")
            })
        }
    }
    // MARK: - 设置视图
    private func setupUI(){
        
        // 01 - 添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        // 02 - 添加约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 85, height: 85))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
        
    }

    //懒加载控件
   
    //背景图片
   private lazy var backImageView: UIImageView = UIImageView(image: UIImage(named:"ad_background"))
    //头像图片
    private lazy var headImageView: UIImageView = {
        let img = UIImageView(image: UIImage(named: "avatar_default_big"))
        img.layer.cornerRadius = 85 / 2
        img.layer.borderColor = themColor.CGColor
        img.layer.borderWidth = 2
        img.clipsToBounds = true
        img.sd_setImageWithURL(NSURL(string: YZMUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        return img
    }()
    // 欢迎回来
    private lazy var messageLabel: UILabel = {
        let lab =  UILabel(textColor: UIColor.darkGrayColor(), textFont: 17)
        lab.textAlignment = .Center
        lab.text = "欢迎回来"
        lab.alpha = 0
        return lab
    }()

    
    
    
}
